﻿
using Microsoft.Xna.Framework.Input;

namespace Tomahawk.Runtime.Input
{
#if WINDOWS
    public sealed class KeyboardManager
    {
        private KeyboardState oldState;
        private KeyboardState currentState;

        public KeyboardManager() 
        {
            oldState = Keyboard.GetState();
            currentState = Keyboard.GetState();
        }

        public void Update(float elapsedTime)
        {
            oldState = currentState;
            currentState = Keyboard.GetState();
        }

        public bool WasKeyDown(Keys[] keys)
        {
            bool allDown = true;
            foreach (Keys key in keys)
            {
                allDown = allDown & oldState.IsKeyDown(key);
            }

            return allDown;
        }

        public bool IsKeyDown(Keys[] keys)
        {
            bool allDown = true;
            foreach (Keys key in keys)
            {
                allDown = allDown & currentState.IsKeyDown(key);
            }

            return allDown;
        }

        public bool IsKeyDown(Keys[] keys, out bool alt, out bool ctrl, out bool shift)
        {
            bool allDown = IsKeyDown(keys);

            alt = currentState.IsKeyDown(Keys.LeftAlt) || currentState.IsKeyDown(Keys.RightAlt);
            ctrl = currentState.IsKeyDown(Keys.LeftControl) || currentState.IsKeyDown(Keys.RightControl);
            shift = currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift);

            return allDown;
        }
    }
#else
    public sealed class KeyboardManager
    {
        public KeyboardManager() 
        {
        }

        public void Update(float elapsedTime)
        {
        }

        public bool IsKeyDown(Keys[] keys)
        {
            return false;
        }

        public bool IsKeyDown(Keys[] keys, out bool alt, out bool ctrl, out bool shift)
        {
            alt = false;
            ctrl = false;
            shift = false;

            return false;
        }
    }
#endif
}
